package com.example.demo;


import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * SpringBootConfiguration 通过@Configuration和@Bean注入IOC容器
 * EnableAutoConfiguration  通过spring.factories实现bean注册
 * ComponentScan  包扫描注解类注册
 */
@EnableCaching
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class})
@MapperScan("com.example.demo.dao")
public class DemoApplication {

    private static final Logger log = LoggerFactory.getLogger(DemoApplication.class);

    private static final String SWAGGER_PAGE = "swagger-ui.html";

    private static final String SERVER_SSL_KEY_STORE = "server.ssl.key-store";

    public static void main(String[] args) throws UnknownHostException {
        SpringApplication app = new SpringApplication(DemoApplication.class);
        Environment env=app.run(args).getEnvironment();
        String serverPort = env.getProperty("server.port");
        String protocol = "http";
        if (env.getProperty(SERVER_SSL_KEY_STORE) != null) {
            protocol = "https";
        }
        log.info("\n----------------------------------------------------------\n\t" +
                        "Application '{}' start up! URLs:\n\t" +
                        "SWAGGER API: \t{}://{}:{}/{}\n\t" +
                        "Profile: \t\t{}\n----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                protocol,
                InetAddress.getLocalHost().getHostAddress(),
                serverPort,
                SWAGGER_PAGE,
                env.getActiveProfiles());
    }
}
